#include "gtest/gtest.h"

#include "FileSize.h"

#include <thread>

/*
 * 1. init file size
 * 2. incremet file size
 * 3. get file size
 *
 */

TEST(FileSizeTest, sample) {
    FileSize fs;
    ASSERT_EQ(fs.size(), 0ul);

    size_t initSize = 100;
    fs.set(initSize);
    ASSERT_EQ(fs.size(), initSize);

    size_t up = 200;
    fs.increase(up);
    ASSERT_EQ(fs.size(), initSize + up);
}

TEST(FileSizeTest, mthreadUp) {
    FileSize fs;
    auto fun = [](FileSize & fs) {
        int i = 0;
        while (i < 100000000) {
            fs.increase(1);
            i++;
        }
    };

    std::thread th1(fun, std::ref(fs));
    std::thread th2(fun, std::ref(fs));

    th1.join();
    th2.join();

    ASSERT_EQ(fs.size(), 200000000ul);
}
